'use strict';
const { validateQuery, presence, isInt } = require('property-validator');

const RecomeData = require('@utils/recomeData');
const { ParameterException } = require('@utils/http-exception');

async function searchValidate(ctx) {
  const { valid, errors } = validateQuery(ctx, [
    presence('code', 'code不能为空'),
    presence('startTime', 'startTime不能为空'),
    presence('endTime', 'endTime不能为空'),
    isInt('pageNum', 'pageNum不能为空'),
    isInt('pageSize', 'pageSize不能为空'),
  ]);
  if (!valid) {
    throw new ParameterException(errors);
  }

  const v = new RecomeData(ctx);
  return v;
}

async function detailHouseValidate(ctx) {
  const { valid, errors } = validateQuery(ctx, [
    presence('id', 'id不能为空'),
  ]);
  if (!valid) {
    throw new ParameterException(errors);
  }

  const v = new RecomeData(ctx);
  return v;
}

module.exports = {
  searchValidate,
  detailHouseValidate,
};
